package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	NickName   string `gorm:"type:varchar(30)"`
	Mobile     string `gorm:"type:varchar(30);not null"`
	Address    string `gorm:"type:varchar(30);not null"`
	Password   string `gorm:"type:varchar(32);not null"`
	WechatCode string `gorm:"type:varchar(30)"`
	Qq         string `gorm:"type:varchar(30)"`
	Email      string `gorm:"type:varchar(30)"`
	HeadImage  string `gorm:"type:varchar(500);not null"`
}

func (u *User) UserAdd(db *gorm.DB) error {
	return db.Debug().Create(u).Error
}

func (u *User) FindUserByMobile(db *gorm.DB, mobile string) error {
	return db.Debug().Where("mobile = ?", mobile).Find(u).Error
}

func (u *User) FindUserById(db *gorm.DB, id int64) error {
	return db.Debug().Where("id = ?", id).First(u).Error
}

func (u *User) UserPerfect(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) FindUserByWechatCode(db *gorm.DB, code string) error {
	return db.Debug().Where("wechat_code = ?", code).Find(u).Error
}
